#include <iostream>


int divide(int a,int b)
{
    if(b == 0)
        throw "除数为0"; //抛出异常
    short s = 1;
    if(b == 1)
        throw s;
    if(b == 2)
        throw 3.14;
    return a / b;
}

int main()
{
    try  //尝试执行某段代码
    {
        std::cout<<divide(1,2)<<std::endl;
    }
    //捕获异常：类型必须要严格匹配(const  short和int)
    catch(char const * str)
    {
        std::cout<<str<<std::endl;
    }
    catch(short a)
    {
        std::cout<<a<<std::endl;
    }
    catch(int a)  //捕获不同类型的多分支异常
    {
        std::cout<<"捕获Int:"<<a<<std::endl;
    }
    catch(...) //捕获其他类型的异常
    {
        std::cout<<"捕获到其他类型的异常\n";
    }
    std::cout<<"继续执行...\n";
    
    return 0;
}